import type { RequestOptions } from '@umijs/max';
import { request } from '@umijs/max';
import { requestConfig } from './config';

const { baseURL } = requestConfig;

export default {
  get: <T>(url: string, opts?: RequestOptions) => {
    return request<T>(url, {
      baseURL,
      method: 'GET',
      ...opts,
    });
  },
  post: <T>(url: string, opts: RequestOptions = {}) => {
    return request<T>(url, {
      baseURL,
      method: 'POST',
      ...opts,
    });
  },
  put: (url: string, opts: RequestOptions = {}) => {
    return request(url, {
      baseURL,
      method: 'PUT',
      ...opts,
    });
  },
  delete: (url: string, opts: RequestOptions = {}) => {
    return request(url, {
      baseURL,
      method: 'DELETE',
      ...opts,
    });
  },
};
